
import uuid
from datetime import datetime
from sqlalchemy import create_engine, select, update,insert ,delete,Integer, String, Float,DateTime
from sqlalchemy.orm import sessionmaker, scoped_session,declarative_base,Mapped,mapped_column,relationship,backref

from .. import MappedBase


def gen_id():
   return uuid.uuid4().hex


class QM_LAB_TH(MappedBase):

    __tablename__ = 'QM_LAB_TEMP_HUMI'
   
    def __repr__(self) -> str:
        return f'<Module QM_LAB_TEMP_HUMI {self.dev_no} {self.station_no} {self.created_at} {self.name} >'
    
    uuid:Mapped[str]=mapped_column(String(32),primary_key=True, default=gen_id,comment='uuid')

    dev_no: Mapped[int] = mapped_column(Integer, nullable=False,comment='机台的编号')
    station_no:Mapped[int]=mapped_column(Integer,nullable=False,comment='站点编号,目前来说,站点编号和机台编号100以内的都是一一对应')

    created_at:Mapped[datetime]=mapped_column(DateTime(timezone=True),nullable=False, comment='拍照时间')
    name:Mapped[str] = mapped_column(String(50),nullable=False,comment='图片的名称,也就是时间戳,可以根据此字典,查到当时的图片')
    state: Mapped[str] = mapped_column(String(20),nullable=False,comment='机台运行状态,运行,闲置,高温,低温')


    temp: Mapped[float] = mapped_column(Float,nullable=True,comment='识别出来的内容,实验温度')
    humi: Mapped[float] = mapped_column(Float,nullable=True,comment='识别出来的内容,实验湿度')

    temp_set: Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,将来换高清摄像头,可以读到温度的设定值,恒温恒湿机,高温实验箱')
    humi_set: Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,将来换高清摄像头,可以读到温度的标准值,,恒温恒湿机,高温实验箱')

    temp_set_upper:Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,可以读到温度的设定值,上限,冷热冲击机')
    temp_set_lower:Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,可以读到温度的设定值,下限,冷热冲击机')

    humi_set_upper:Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,可以读到湿度的设定值,上限,冷热冲击机')
    humi_set_lower:Mapped[float] = mapped_column(Float,nullable=True,comment='预留栏位,可以读到湿度的设定值,下限,冷热冲击机')


    abnormal:Mapped[str] = mapped_column(String(50),nullable=True,comment='机台的异常情况,在运行状态,摄像头读不到温湿度,会在这里填写异常情况')

